(define (display-times s n)
  (if (<= n 0)
      #f
      (begin
        (display s)
        (display-times s (- n 1)))))

(define (pass-col cols maxes)
  (if (null? cols)
      (lambda () (newline))
      (let* ((col (car cols))
             (col-max (car maxes))
             (col-len (string-length col))
             (col-max* (max col-len (unbox col-max)))
             (k (pass-col (cdr cols) (cdr maxes))))
        (set-box! col-max col-max*)
        (lambda ()
          (display col)
          (display-times " " (+ 1 (- (unbox col-max) col-len)))
          (k)))))

(define (pass1 table maxes)
  (if (null? table)
      (lambda () #f)
      (let* ((row (car table))
             (col (pass-col row maxes))
             (k (pass1 (cdr table) maxes)))
        (lambda () (col) (k)))))

(define (print-table table)
  (let ((maxes (map (lambda (col) (box 0)) (car table))))
    ((pass1 table maxes))))
